<?php
  require 'salt_func.php';

  $action = $_POST["action"];

  if ($action == "pkginstall") {
      $host = $_POST["host"];
      $port = $_POST["port"];
      $token = $_POST["token"];
      $pkg = $_POST["pkg"];
      $tgt = $_POST["tgt"];
      echo "<h3>install test </h3>";
      echo "master: $host<br> port: $port<br> token: $token<br>  install: $pkg<br> target host(s): $tgt <br>";
      $result=salt_pkg_install($host, $port, $token, $tgt, $pkg);
      echo "<h3>test result</h3>";
      var_dump($result);
  } else {
      $user = $_POST["user"];
      $pass = $_POST["pass"];
      $host = $_POST["host"];
      $port = $_POST["port"];

      print "<h3>login</h3>";
      print "user: $user <br> pass: $pass <br> host: $host <br> port: $port<br>";
      $token = salt_login($host, $port, $user, $pass);
      print "token: $token <br>";
    
      print "<h3>test.ping </h3>";
      $result=salt_test_ping($host, $port, $token, "gb*");
      var_dump($result);
    
      print "<h3>pkg.install </h3>";
      echo <<< eof1
      <form action="test.php" method="post"> 
        package name  <input type="text" name="pkg" value="salt"><br>
        target host(s)  <input type="text" name="tgt" value="gb*"/><br>
        <input type="hidden" name="action" value="pkginstall">
        <input type="hidden" name="host" value="$host">
        <input type="hidden" name="port" value="$port">
        <input type="hidden" name="token" value="$token">
        <input type="submit" value="install">
      </form>
eof1;
  }

?>
